# Initial process that execs /init.
# This code runs in user space.

#include "include/syscall.h"
#include "include/fcntl.h"
#define CONSOLE 1

.globl start
start:
        # dev(O_RDWR, CONSOLE, 0)
        li a0, O_RDWR
        li a1, CONSOLE
        li a2, 0
        li a7, SYS_dev
        ecall
        # dup(0) -> stdout
        la a0, 0
        li a7, SYS_dup
        ecall
        # dup(0) -> stderr
        la a0, 0
        li a7, SYS_dup
        ecall
        # exec()
        la a0, init
        la a1, argv
        li a7, SYS_exec
        ecall

# for(;;) exit();
exit:
        li a7, SYS_exit
        ecall
        jal exit

# char init[] = "/init\0";
init:
  .string "busybox"

# char *argv[] = { init, 0 };
.p2align 2
argv:
  .long init
  .long 0
